<?php
class Administrator_advertisement_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }	
	
	/*Content Management*/
	function content_management_add()
	{
		$ads_name = $this->input->post('ads_name');
		$is_music = $this->input->post('is_music');
		$is_video = $this->input->post('is_video');
		$is_movie = $this->input->post('is_movie');
		$start_date = $this->input->post('start_date');
		$end_date = $this->input->post('end_date');
		$ads_vast = $this->input->post('ads_vast');
		$ads_weight = $this->input->post('ads_weight');
		$ads_impression = $this->input->post('ads_impression');
		$limit_per_day = $this->input->post('limit_per_day');
		$datetime = date('Y-m-d H:i:s');
		
		//Insert advertisement_content
		$data = array(
			'ads_name' => $ads_name,
			'is_music' => $is_music,
			'is_video' => $is_video,
			'is_movie' => $is_movie,
			'start_date' => convertDatetime($start_date),
			'end_date' => convertDatetime($end_date),
			'ads_vast' => $ads_vast,
			'ads_weight' => $ads_weight,
			'ads_impression' => $ads_impression,
			'limit_per_day' => $limit_per_day,
			'update_by' => $this->session->userdata('username'),			
			'create_date' => $datetime,
			'update_date' => $datetime
		);
		$this->db->insert('ads',$data);
	}
	
	function content_management_edit($ads_id)
	{
		$ads_name = $this->input->post('ads_name');
		$is_music = $this->input->post('is_music');
		$is_video = $this->input->post('is_video');
		$is_movie = $this->input->post('is_movie');		
		$start_date = $this->input->post('start_date');
		$end_date = $this->input->post('end_date');
		$ads_vast = $this->input->post('ads_vast');
		$ads_weight = $this->input->post('ads_weight');
		$ads_impression = $this->input->post('ads_impression');
		$limit_per_day = $this->input->post('limit_per_day');
		$datetime = date('Y-m-d H:i:s');
		
		//Update advertisement_content
		$data = array(
			'ads_name' => $ads_name,
			'is_music' => $is_music,
			'is_video' => $is_video,
			'is_movie' => $is_movie,			
			'start_date' => convertDatetime($start_date),
			'end_date' => convertDatetime($end_date),
			'ads_vast' => $ads_vast,
			'ads_weight' => $ads_weight,
			'ads_impression' => $ads_impression,
			'limit_per_day' => $limit_per_day,
			'update_by' => $this->session->userdata('username'),			
			'update_date' => $datetime
		);
		$this->db->update('ads',$data,array('ads_id' => $ads_id));				
	}	
	
	function content_management_delete()
	{
		$id = $this->input->post('id');
		foreach($id as $value):
			$tables = array('ads');
			$this->db->where('ads_id', $value);
			$this->db->delete($tables);			
		endforeach;			
	}
	
	/*Upload Mp4*/
	function upload_mp4()
	{
		$ads_path = $this->upload_folder."../../ads/";
		$uploadify_store = explode(',',$this->input->post('uploadify_store'));
		
		if(!empty($uploadify_store[0])) foreach($uploadify_store as $value):
			//Delete Old File
			@unlink($ads_path.$value);
			//Copy File
			copy($this->temp_folder.$value,$ads_path.$value);
			//Delete Temp
			@unlink($this->temp_folder.$value);
		endforeach;
	}
	
	function upload_mp4_delete()
	{
		$ads_path = $this->upload_folder."../../ads/";
		$id = $this->input->post('id');
		foreach($id as $value):
			@unlink($ads_path.$value);		
		endforeach;			
	}	
}

?>